﻿using System.Web.Mvc;
using System.Web.Routing;
using Omu.Awesome.Mvc;
using Qu.SeniorProject.WebApp;
using System.Web.Http;

namespace Qu.SeniorProject.WebUI
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Reports", // Route name
                "Reports/{id}", // URL with parameters
                new { controller = "Home", action = "Reports", id = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "documentDeliverableUrlSubmission", // Route name
                "document/DeliverableUrlSubmission", // URL with parameters
                new { controller = "document", action = "DeliverableUrlSubmission", id = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "documentUpload", // Route name
                "document/Upload", // URL with parameters
                new { controller = "document", action = "Upload", id = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "document", // Route name
                "document/{id}", // URL with parameters
                new { controller = "document", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "schedule", // Route name
                "schedule", // URL with parameters
                new { controller = "schedule", action = "Index" } // Parameter defaults
            );

            routes.MapRoute(
                "bschedule", // Route name
                "bschedule/{id}", // URL with parameters
                new { controller = "schedule", action = "Index", id = "M" } // Parameter defaults
            );

            routes.MapRoute(
                "gschedule", // Route name
                "gschedule/{id}", // URL with parameters
                new { controller = "schedule", action = "Index", id = "F" } // Parameter defaults
            );



            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            ModelMetadataProviders.Current = new AwesomeModelMetadataProvider();
            // Workaround to fix MVC3 R2 Bug
            // http://weblogs.asp.net/scottgu/archive/2010/12/14/update-on-asp-net-mvc-3-rc2-and-a-workaround-for-a-bug-in-it.aspx
            //ModelMetadataProviders.Current = new DataAnnotationsModelMetadataProvider();

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            WebApiConfig.Register(GlobalConfiguration.Configuration);

        }
    }
}